<?php
declare(strict_types=1);
// 用户信息
namespace app\tjy_v1\controller;

use app\tjy_v1\model\User as MYSQL; //导入模型

class User
{
    // 获取用户信息
    public function info()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "获取用户信息",
            'query' => $query,
            'token' => cache("login@token"),
            "db" => [
                "user_id" => "user_id",
                "mobile" => "1380*****00",//手机
                "email" => "13800138000@emailemail",
                "balance" => "0.00",//帐户余额
                "frozen" => "0.00",//冻结金额
                "integral" => "0.00",//积分
                "nick_name" => "用户" . mt_rand(100, 9999),//昵称
                "avatar" => "https://thirdwx.qlogo.cn/mmopen/vi_32/Q3auHgzwzM4xDMSqvp3uCBOf7cMiabO4Z2YmDPEW7JALH1ohkwb5iardahIoXiakNk5yIZjs1KwYUdrHKsO2icDic4g/132",//头像
                // "avatar" => "/static/user2.png",//头像D:\uniapp\minishop\unpackage\dist\dev\mp-weixin\static\tabbar
                "birthday" => "0000-00-00",
                "gender" => 1,
                "status" => 1,
                "is_delete" => 0,
                "delete_time" => "0000-00-00 00:00:00",
                "update_time" => "2021-03-31 01:10:58",
                "create_time" => "2021-03-31 01:10:58"
            ]
        ];
        return json($apidb);
    }
    // 修改用户信息
    public function up()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "修改用户信息",
            'query' => $query,
        ];
        return json($apidb);
    }

    // 获取我的地址列表
    public function Address()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "获取我的地址列表",
            'query' => $query,
            'token' => cache("login@token"),
            "db" => [
                "total" => 1,
                "list" => [
                    [
                        "id" => 139,
                        "address_id" => "208723610882748418",
                        "user_id" => "164904338662182914",
                        "contact" => "d",
                        "contact_number" => "13800138000",
                        "gender" => 1,
                        "province" => "120000",
                        "city" => "",
                        "district" => "",
                        "street" => "",
                        "address" => "ASd",
                        "house_number" => "ads",
                        "longitude" => "",
                        "latitude" => "",
                        "is_default" => 1,
                        "status" => 1,
                        "is_delete" => 0,
                        "update_time" => "2021-07-29 23:13:06",
                        "create_time" => "2021-07-29 23:13:06",
                        "province_name" => "天津市",
                        "city_name" => null,
                        "district_name" => null,
                        "street_name" => null,
                        "full_address" => "天津市ASdads"
                    ]
                ]
            ]
        ];
        return json($apidb);
    }
    // 新增用户地址
    public function AddressNEW()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "新增用户地址",
            'query' => $query,
            'token' => cache("login@token"),
        ];
        return json($apidb);
    }
    // 修改一条用户地址
    public function AddressUP()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "修改一条用户地址",
            'query' => $query,
            'token' => cache("login@token"),
        ];
        return json($apidb);
    }
    // 修改一条用户地址为默认地址
    public function AddressDefault()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "修改一条用户地址为默认地址",
            'query' => $query,
            'token' => cache("login@token"),
        ];
        return json($apidb);
    }

    // 返回一条用户地址
    public function AddressID()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "返回一条用户地址",
            'query' => $query,
            'token' => cache("login@token"),
            "db" => [
                "id" => 139,
                "address_id" => "208723610882748418",
                "user_id" => "164904338662182914",
                "contact" => "d",
                "contact_number" => "13800138000",
                "gender" => 1,
                "province" => "120000",
                "city" => "",
                "district" => "",
                "street" => "",
                "address" => "ASd",
                "house_number" => "ads",
                "longitude" => "",
                "latitude" => "",
                "is_default" => 1,
                "status" => 1,
                "is_delete" => 0,
                "update_time" => "2021-07-29 23:13:06",
                "create_time" => "2021-07-29 23:13:06",
                "province_name" => "天津市",
                "city_name" => null,
                "district_name" => null,
                "street_name" => null,
                "full_address" => "天津市ASdads"
            ]
        ];
        return json($apidb);
    }

    // 删除用户地址
    public function AddressDelete()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "删除用户地址",
            'query' => $query,
            'token' => cache("login@token"),
        ];
        return json($apidb);
    }

    // 地区选择器数据
    public function RegionDB()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "地区选择器数据",
            'query' => $query,
            'token' => cache("login@token"),
            "db" => [
                "name" => "所在地区选择器数据",
                "list" => [
                    [
                        "value" => "110000",
                        "label" => "北京市",
                        "leaf" => 1
                    ],
                    [
                        "value" => "120000",
                        "label" => "天津市",
                        "leaf" => 1
                    ],
                    [
                        "value" => "130000",
                        "label" => "河北省",
                        "leaf" => 12
                    ],
                    [
                        "value" => "140000",
                        "label" => "山西省",
                        "leaf" => 11
                    ],
                    [
                        "value" => "150000",
                        "label" => "内蒙古自治区",
                        "leaf" => 12
                    ],
                    [
                        "value" => "210000",
                        "label" => "辽宁省",
                        "leaf" => 14
                    ],
                    [
                        "value" => "220000",
                        "label" => "吉林省",
                        "leaf" => 9
                    ],
                    [
                        "value" => "230000",
                        "label" => "黑龙江省",
                        "leaf" => 13
                    ],
                    [
                        "value" => "310000",
                        "label" => "上海市",
                        "leaf" => 1
                    ],
                    [
                        "value" => "320000",
                        "label" => "江苏省",
                        "leaf" => 13
                    ],
                    [
                        "value" => "330000",
                        "label" => "浙江省",
                        "leaf" => 11
                    ],
                    [
                        "value" => "340000",
                        "label" => "安徽省",
                        "leaf" => 16
                    ],
                    [
                        "value" => "350000",
                        "label" => "福建省",
                        "leaf" => 9
                    ],
                    [
                        "value" => "360000",
                        "label" => "江西省",
                        "leaf" => 11
                    ],
                    [
                        "value" => "370000",
                        "label" => "山东省",
                        "leaf" => 17
                    ],
                    [
                        "value" => "410000",
                        "label" => "河南省",
                        "leaf" => 18
                    ],
                    [
                        "value" => "420000",
                        "label" => "湖北省",
                        "leaf" => 14
                    ],
                    [
                        "value" => "430000",
                        "label" => "湖南省",
                        "leaf" => 14
                    ],
                    [
                        "value" => "440000",
                        "label" => "广东省",
                        "leaf" => 21
                    ],
                    [
                        "value" => "450000",
                        "label" => "广西壮族自治区",
                        "leaf" => 14
                    ],
                    [
                        "value" => "460000",
                        "label" => "海南省",
                        "leaf" => 5
                    ],
                    [
                        "value" => "500000",
                        "label" => "重庆市",
                        "leaf" => 2
                    ],
                    [
                        "value" => "510000",
                        "label" => "四川省",
                        "leaf" => 21
                    ],
                    [
                        "value" => "520000",
                        "label" => "贵州省",
                        "leaf" => 9
                    ],
                    [
                        "value" => "530000",
                        "label" => "云南省",
                        "leaf" => 16
                    ],
                    [
                        "value" => "540000",
                        "label" => "西藏自治区",
                        "leaf" => 7
                    ],
                    [
                        "value" => "610000",
                        "label" => "陕西省",
                        "leaf" => 10
                    ],
                    [
                        "value" => "620000",
                        "label" => "甘肃省",
                        "leaf" => 14
                    ],
                    [
                        "value" => "630000",
                        "label" => "青海省",
                        "leaf" => 8
                    ],
                    [
                        "value" => "640000",
                        "label" => "宁夏回族自治区",
                        "leaf" => 5
                    ],
                    [
                        "value" => "650000",
                        "label" => "新疆维吾尔自治区",
                        "leaf" => 15
                    ],
                    [
                        "value" => "710000",
                        "label" => "台湾省",
                        "leaf" => 0
                    ],
                    [
                        "value" => "810000",
                        "label" => "香港特别行政区",
                        "leaf" => 0
                    ],
                    [
                        "value" => "820000",
                        "label" => "澳门特别行政区",
                        "leaf" => 0
                    ]
                ],
                "total" => 34
            ]
        ];
        return json($apidb);
    }

    // 个人中心页数据
    public function personal()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "个人中心页数据",
            'query' => $query,
            'token' => cache("login@token"),
            'db' => [
                "user_info" => [
                    "name" => "用户中心-用户信息",
                    "browse" => 0,
                    "collect" => 0
                ],
                "user_statistics" => [
                    "name" => "用户中心-账户余额块",
                    "db" => [
                        [
                            "label" => '账户余额',
                            "value" => 40,
                            "field" => 'balance',
                            "tabCode" => '/pages/wallet/wallet'
                        ],
                        [
                            "label" => '积分',
                            "value" => 760,
                            "field" => 'integral',
                            "tabCode" => '/pages/wallet/integral'
                        ],
                        [
                            "label" => '我的收藏',
                            "value" => 8760,
                            "field" => 'collect',
                            "tabCode" => '/pages/mine/collect'
                        ],
                        [
                            "label" => '浏览记录',
                            "value" => 670,
                            "field" => 'browse',
                            "tabCode" => '/pages/mine/browse'
                        ]
                    ]
                ],
                "user_order" => [
                    "name" => "用户中心-订单信息",
                    "db" => [
                        [
                            "label" => '待付款',
                            "tabCode" => 'waitPay',
                            "icon" => '/static/order/wait_pay.png',
                            "count" => 2,
                        ],
                        [
                            "label" => '待发货',
                            "tabCode" => 'waitSend',
                            "icon" => '/static/order/wait_send.png',
                            "count" => 28,
                        ],
                        [
                            "label" => '待收货',
                            "tabCode" => 'waitConfirm',
                            "icon" => '/static/order/all.png',
                            "count" => 89,
                        ],
                        [
                            "label" => '待评论',
                            "tabCode" => 'waitComment',
                            "icon" => '/static/order/wait_comment.png',
                            "count" => 89,
                        ]
                    ],
                ],
                "user_profit" => [
                    "name" => "用户中心-我的收益",
                    "show" => true,//前端是否显示模块
                    "withdraw" => "894.00",//可提现金额
                    "db" => [
                        [
                            "label" => '佣金',
                            "tabCode" => 'waitPay',
                            "icon" => '/static/order/wait_pay.png',
                            "count" => "+2",
                        ],
                        [
                            "label" => '小费',
                            "tabCode" => 'waitSend',
                            "icon" => '/static/order/wait_send.png',
                            "count" => "+28",
                        ],
                        [
                            "label" => '货款',
                            "tabCode" => 'waitConfirm',
                            "icon" => '/static/order/all.png',
                            "count" => "+89",
                        ],
                        [
                            "label" => '扣税',
                            "tabCode" => 'waitComment',
                            "icon" => '/static/order/wait_comment.png',
                            "count" => "-55",
                        ]
                    ],
                ],
                "user_tools" => [
                    "name" => "用户中心-常用工具",
                    "db" => [
                        [
                            "label" => '我的地址',
                            "icon" => '/static/mine/6.png',
                            "tabCode" => '/pages/mine/address'
                        ],
                        [
                            "label" => '优惠券',
                            "icon" => '/static/mine/6.png',
                            "tabCode" => '/pages/coupon/mine'
                        ],
                        [
                            "label" => '邀请用户',
                            "icon" => '/static/mine/6.png',
                            "tabCode" => '/pages/mine/invite'
                        ],
                        [
                            "label" => '系统设置',
                            "icon" => '/static/mine/6.png',
                            "tabCode" => '/pages/setting/setting'
                        ]
                    ]
                ],
            ]
        ];
        return json($apidb);
    }

    // 用户头像照片上传
    public function ProfilePhotoUpload()
    {
        $query = request()->param(); //请求参数
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "用户头像照片上传",
            'query' => $query,
            'token' => cache("login@token"),
            "db" => [
                "adapter" => "qiniu",
                "upload_token" => "EYS9On3BWuixb27FqwmggSk2pw1GjE92606U7Z6x:m7r9iKllXvP66pQhbKi0u02_uXg=:eyJjYWxsYmFja1VybCI6Imh0dHA6XC9cL2xpdHRsZS1tYWxsLmRlbW8udGFvc2hhdGVjLmNvbVwvdjFcL3VwbG9hZFwvcWlOaXVVcGxvYWRDYWxsYmFjayIsImNhbGxiYWNrQm9keSI6IntcIm5hbWVcIjpcIiQoZm5hbWUpXCIsXCJrZXlcIjpcIiQoa2V5KVwiLFwic2l6ZVwiOlwiJChmc2l6ZSlcIixcIndcIjpcIiQoaW1hZ2VJbmZvLndpZHRoKVwiLFwiaFwiOlwiJChpbWFnZUluZm8uaGVpZ2h0KVwiLFwiaGFzaFwiOlwiJChldGFnKVwiLFwidHlwZVwiOlwiJChtaW1lVHlwZSlcIixcImRpcmVjdG9yeVwiOlwiJCh4OmRpcmVjdG9yeSlcIn0iLCJzY29wZSI6ImxpdHRsZS1tYWxsIiwiZGVhZGxpbmUiOjE2MzIyMjMyOTZ9",
                "upload_url" => "http://127.0.0.1:81/tjyv1/user/Upload",//用户头像照片上传地址
                "upload_base64_url" => "http://up-z2.qiniu.com/putb64/-1",
                "upload_form_field" => "file",
                "is_compress" => 1
            ]
        ];
        return json($apidb);
    }

    // 接受用户头像照片上传并保存
    public function Upload()
    {
        // 内置的上传只是上传到本地服务器，上传到远程或者第三方平台的话需要安装额外的扩展。
        // 上传到远程需要安装think-filesystem扩展，首先使用下面的命令安装。
        // composer require topthink/think-filesystem
        $query = request()->param(); //请求参数
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('image');
        // 上传到本地服务器
        $savename = \think\facade\Filesystem::putFile('topic', $file);
        $apidb = [
            'code' => 200,
            'time' => time(),
            'msg' => "接受用户头像照片上传并保存",
            'query' => $query,
            'token' => cache("login@token"),
            'db' => [
                'image' => $savename
            ]
        ];
        return json($apidb);
    }


}
